package com.dqhl.smartstable.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dqhl.smartstable.R;
import com.dqhl.smartstable.model.OperationLog;
import com.dqhl.smartstable.util.TimeUtils;
import com.dqhl.smartstable.util.ViewHolder;

import java.util.List;

/**
 * Created by mac on 16/10/18.
 * 操作日志列表adapter
 */
public class OperationLogListAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater inflater;
    private List<OperationLog> operationLogList;

    public OperationLogListAdapter(Context context, List<OperationLog> operationLogList){
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.operationLogList = operationLogList;
    }

    @Override
    public int getCount() {
        return operationLogList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = inflater.inflate(R.layout.item_lv_operation_log, parent, false);
        }
        TextView tv_log_info = ViewHolder.get(convertView, R.id.tv_log_info);
        TextView tv_time = ViewHolder.get(convertView, R.id.tv_time);
//        case_state箱子状态1/2/4/3/5:无报警/撞击报警/见光报警/位移报警/未知报警,action_type=处理人2/1:用户/管理员
        OperationLog operationLog = operationLogList.get(position);
        String case_state = operationLog.getCase_state();
        String strLogInfo = "";
        switch (case_state){
            case "1":
                strLogInfo = "我的安全箱无警报";
                break;
            case "2":
                strLogInfo = "我的安全箱发生撞击报警";
                break;
            case "3":
                strLogInfo = "我的安全箱发生见光报警";
                break;
            case "4":
                strLogInfo = "我的安全箱发生位移报警";
                break;
            case "5":
                strLogInfo = "我的安全箱发生未知报警";
                break;
        }
        tv_log_info.setText(strLogInfo);
        String strTime = TimeUtils.timeStamp2Date(operationLog.getCreate_time(),"yyyy-MM-dd HH:mm");
        tv_time.setText(strTime);

        return convertView;
    }
}
